## function ##
single_qc <- function(x, y, plotID, main, col, ylab_histo, ylab_box, xlab) 
{
################################################################################
##  
##  This program plots a histogram and a boxplot for the temperature from April 
##  2011. Further it calculates the standard variance and the mean of the data
##  It is possible to pass further standard lattice arguments. 
##  
##  parameters are as follows:
##  x and y objects to be plotted (no default)
##    x = t_wxt --> air temperature (2m)
##    y = st_wxt --> soil temperature (10cm)
##  plotID = conditioning variable (optional - no default)
##  col = colour of the histogram
##  no default settings
##
## there are still some faults: standard variance, mean and median aren??t be 
## printed. Furthermore the x-intercepts of the histograms are wrong. 
################################################################################
##
##  Copyright (C) 2011 Steffi Instinsky, Simon Lange, Melanie Schnelle
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##  Please send any comments, suggestions, criticism, or (for our sake) bug
##  reports to eimar.teaching@gmail.com
##
################################################################################                        
 
  ## define and combine histograms ##
  histo_twxt <- histogram(~ x | plotID, freq = T, col = col, ylab = ylab_histo, 
                         subset = plotID == "cof3", xlab = "cof3")
  histo_stwxt <- histogram(~ y | plotID, nint = 100, freq = T, col = col, ylab = ylab_histo,
                         subset = plotID == "cof3", xlab = "cof3")
  combohisto <- c(histo_twxt, histo_stwxt, layout = c(2,1))
 
  ## define standard variance ##
  sd_twxt <- sd(x)
  sd_stwxt <- sd(y)
  
  # combine standard deviance <- c(sd_twxt, sd_stwxt) #
  combosd <- c(sd_twxt, sd_stwxt)
    combosd_2 <- 2*combosd
    combosd_3 <- 3*combosd
  combosd_new <- c(combosd, combosd_2, combosd_3)
  combosd_new
     
  ## define mean ##
  mean_twxt <- mean(x)
  mean_stwxt <- mean(y)
  
  #combine mean <- c(mean_twxt, mean_stwxt)
  combomean<- c(mean_twxt, mean_stwxt)
  combomean
  
  ## define median ##
  median_twxt <- median(x)
  median_stwxt <- median(y)
  
  # combine median #
  combomedian <- c(median_twxt, median_stwxt)
  ## define boxplot ##
  boxplot_t_wxt <- boxplot(x, main = "Air temperature", ylab = ylab_box, 
                           outline = F)
  boxplot_st_wxt <- boxplot(y, main = "Soil temperature", ylab = ylab_box,
                            outline = F)
  
  # combine boxplots #
  comboboxplot <- c(boxplot_t_wxt, boxplot_st_wxt, layout = c(2,1))
  
  ## print all ##
  return(print(combohisto))
  return(print(combosd_new))
  return(print(combomean))
  return(print(comboboxplot))

}
## Example
  data <- read.csv("C:/Users/Melanie/Desktop/RKurs/development/eimar-vpspph-ws2011/sms/dataset_single_qc_orig(1).csv")

#single_qc(data$t_wxt, data$st_wxt, plotID = data$plotID, col = "red")

  single_qc(x = data$t_wxt,
            y = data$st_wxt,
            plotID = data$plotID,
            col = "red",
            ylab_histo = "contribution",
            ylab_box = "??C",
            xlab = "temperature"
          )
